package controller;

import java.util.List;

import model.Hospede;
import dao.DAOHospede;

public class HospedeController {

	public Hospede criarHospede(String nome, String telefone, String endereco,
			String email, long cpf) {
		
		DAOHospede dh = new DAOHospede();

		Hospede h = new Hospede(nome, telefone, endereco, email, cpf);
		dh.persist(h);
		dh.commit();
		
		return dh.findLast();
	}

	public void excluirHospede(int id) {
		DAOHospede dh = new DAOHospede();
		Hospede h = dh.findById(id);
		dh.remove(h);
		dh.commit();
	}

	public void excluirHospede(long cpf) {
		DAOHospede dh = new DAOHospede();
		Hospede h = dh.findByCpf(cpf);
		dh.remove(h);
		dh.commit();
	}

	public Hospede findHospede() {
		return null;
	}
	
	public List<Hospede> getAllHospedes(){
		return new DAOHospede().findAll();
	}
	
	public Hospede checarPendencias(int idHospede) {
		DAOHospede daoHospede = new DAOHospede();
		Hospede hospede = daoHospede.findById(idHospede);
		if(hospede.getHospedagemAtual() != null || hospede.getUltimaHospedagem() != null && !hospede.getUltimaHospedagem().isQuitada())
			return null;
		
		return hospede;
	}

}
